bpo-38030: Fix os.stat failures on block devices on Windows - #15681
Conversation
|
Thanks @zooba for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
|
GH-15682 is a backport of this pull request to the 3.8 branch. |
| error = retval ? GetLastError() : 0; | ||
| if (!CloseHandle(hFile)) { | ||
| retval = -1; | ||
| } else if (retval) { |
There was a problem hiding this comment.
Have you had a problem with this? The normal path for the internal implementation of CloseHandle is to call status = NtClose(handle). If the return status is successful, it just returns TRUE. Otherwise Windows sets the last error from the status code (i.e. RtlNtStatusToDosError, etc) and returns FALSE. It's not going to modify our thread's last error value if it succeeds.
There was a problem hiding this comment.
No, just being overly defensive. There are other functions that (incorrectly) change the last error, and it's easier to be consistent about preserving it than to rely on a not-strictly-followed convention.
There was a problem hiding this comment.
In particular, for others who come in and copy my code without necessarily checking severe edge cases like this :)
https://bugs.python.org/issue38030